package com.wh.beans.custom;


import com.legend.utils.StringUtils;
import com.wh.model.CustomField;

import java.text.MessageFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 选择日期时间
 * @author Administrator
 *
 */
public class SelectDatetime implements ICustomLabel {

	@Override
	public String getCustomLabel(CustomField field, LabelType type) {
		String label = "", template = "";
		String fieldLittleName=StringUtils.getFieldLittleCamel(field.getFieldDbName());
		String fieldBigName= StringUtils.getFieldBigCamel(field.getFieldDbName());
		switch (type) {
		case add:
			template = "<input type='text' id=\"txt{0}\" name=\"{1}\" data-options=\"'{'value:\''{2}\'''}'\"  data-options=\"editable:false\" class=\"easyui-datetimebox\" style=\"width:120px\"/>";
			SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			String now = df.format(new Date());
			label = MessageFormat.format(template, fieldBigName, fieldLittleName, now);
			break;
		case edit:
			template = "<input type='text' id=\"txt{0}\" name=\"{1}\" value=\"{2}\" data-options=\"editable:false\" class=\"easyui-datetimebox\" style='width:120px'/>";
			label = MessageFormat.format(template,fieldBigName,fieldLittleName, "${info.data."+fieldLittleName+"}");
			break;
		case view:
			template="$'{'info.data.{0}?string('yyyy-MM-dd HH:mm:ss')'}'";
			label=MessageFormat.format(template, fieldLittleName);
			break;
		default:
			break;
		}
		return label;
	}
}
